﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVC4Shop.dao;
using MVC4Shop.Models;

namespace MVC4Shop.Controllers
{
    public class ColorController : Controller
    {
        //
        // GET: /Color/

        public ActionResult Index()
        {
            return View(ColorDAO.GetAll());
        }

        public ActionResult Create()
        {

            return View();
        }

        [HttpPost]
        public ActionResult Create(FormCollection collection, HttpPostedFileBase file)
        {
            ColorModel model = new ColorModel();
            model.name = collection["name"].ToString();
            model.image = "";
            if (file != null && file.ContentLength > 0)
            {
                Console.WriteLine("success");
            }
            if (ColorDAO.Insert(model))
            {
                Console.WriteLine("success");
            }
            else
            {
                Console.WriteLine("Fails");
            }

            return View("index");
        }

        public ActionResult Edit(int id)
        {

            return View();
        }

        //
        // POST: /Size/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                ColorModel model = new ColorModel();
                model.name = collection["name"].ToString();
                model.id = id.ToString();
                ColorDAO.Edit(model);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Size/Delete/5

        public ActionResult Delete(int id)
        {

            return View();
        }

        //
        // POST: /Size/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                ColorDAO.Delete(id.ToString());
                return RedirectToAction("Index");

            }
            catch
            {
                return View();
            }
        }

    }
}
